package com.wms.shop.controller;

import com.alibaba.fastjson.JSONObject;
import com.wms.common.core.utils.SecurityUtils;
import com.wms.common.core.web.controller.BaseController;
import com.wms.common.core.web.domain.AjaxResult;
import com.wms.shop.domain.Order;
import com.wms.shop.domain.vo.PayOrderVo;
import com.wms.shop.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


/**
 * 商城订单Controller
 *
 * @author zzm
 * @date 2021-12-19
 */
@RestController
@RequestMapping("/wx/order")
public class WxOrderController extends BaseController
{
    @Autowired
    private IOrderService orderService;



    /**
     * 查询商城订单列表
     */
    @GetMapping("/list")
    public AjaxResult list(Order order)
    {
        order.setUserId(SecurityUtils.getUserId());
        List<Order> list = orderService.selectWxOrderList(order);
        return AjaxResult.success(list);
    }

    /**
     * 获取商城订单详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(orderService.selectOrderById(id));
    }

    /**
     * 新增商城订单
     */
    @PostMapping(value = "save")
    public AjaxResult add(@RequestBody PayOrderVo payOrderVo)
    {
      return AjaxResult.success(orderService.insertOrder(payOrderVo));
    }

    /**
     * 取消商城订单
     */
    @PutMapping(value = "cancel/{id}")
    public AjaxResult cancel(@PathVariable Long id)
    {
        return toAjax(orderService.cancel(id));
    }


    /**
     * 确认收货
     */
    @PutMapping(value = "receive/{id}")
    public AjaxResult receive(@PathVariable Long id)
    {
        return toAjax(orderService.receive(id));
    }


    /**
     * 删除商城订单
     */
    @DeleteMapping(value = "delete/{id}")
    public AjaxResult delete(@PathVariable Long id)
    {
        return toAjax(orderService.deleteOrderById(id));
    }


    @PostMapping(value = "unifiedOrder")
    public AjaxResult unifiedOrder(@RequestBody Map<String,String> map){
        String id = map.get("id");
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("timeStamp", "2344343");
        jsonObject.put("nonceStr","3334334333");
        jsonObject.put("packageValue", "929839829");
        jsonObject.put("signType","MD5");
        jsonObject.put("paySign","232eewewe23233");
        return AjaxResult.success(jsonObject);
    }


}
